﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Data.Activation;

namespace StyleMVVM.DependencyInjection.Impl
{
	internal class ArrayExportStrategy<T> : IExportStrategy
	{
		private string lookupString;
		private Action<IInjectionContext, string, List<T>, FilterExport> importMethod;

		public ArrayExportStrategy(Action<IInjectionContext, string, List<T>, FilterExport> importMethod)
		{
			lookupString = typeof(T).FullName;
			this.importMethod = importMethod;
			ActivationType = typeof(ReadOnlyCollection<T>);
			ExportNames = new[]
				              {
					              typeof(T[]).FullName
				              };
			ExportedTypes = new[]
								  {
									  typeof(T[])
								  };
		}

		public IDependencyInjectionContainer Container { get; set; }

		public IActivationService ActivationService { get; set; }

		public object Activate(IInjectionContext injectionContext, object[] constructorParams)
		{
			List<T> returnValue = new List<T>();

			importMethod(injectionContext, lookupString, returnValue, null);

			return returnValue.ToArray();
		}

		public IEnumerable<string> ExportNames { get; set; }

		public IEnumerable<Type> ExportedTypes { get; set; }

		public Type ActivationType { get; private set; }

		public bool ExternallyOwned { get; set; }

		public BeforeDisposalCleanupDelegate DisposalCleanupDelegate { get; set; }

		public ILifeCycleContainer LifeCycleContainer { get; set; }

		public bool Suspendable { get; set; }

		public ExportEnvironment Environment { get; set; }

		public int Priority { get; set; }

		public bool IsCoreExport { get; set; }

		public int CoreExportStartOrder { get; set; }

		public void Initialize()
		{
			
		}

		public void AddPiplineHandler(IExportPipelineHandler pipelineHandler)
		{
			
		}

		public void RemovePipelineHandler(IExportPipelineHandler pipelineHandler)
		{

		}

		public bool MeetsConditions(IDependencyInjectionContainer container, IInjectionContext injectionContext)
		{
			return true;
		}

		public void AddCondition(IExportCondition condition)
		{

		}

		public void RemoveCondition(IExportCondition condition)
		{

		}

		public IEnumerable<IExportCondition> Conditions()
		{
			return new IExportCondition[0];
		}

		public IEnumerable<KeyValuePair<string, object>> Metadata
		{
			get { return new KeyValuePair<string, object>[0]; }
			set { }
		}

		public IEnumerable<EnrichWithDelegate> EnrichWithDelegates { get; set; }
	}
}
